package com.ruoyi.project.loan.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.loan.domain.ApplicationDocument;
import com.ruoyi.project.loan.service.IApplicationDocumentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 申请材料Controller
 *
 * @author ruoyi
 * @date 2025-11-11
 */
@RestController
@RequestMapping("/loan/document" )
public class ApplicationDocumentController extends BaseController {
    @Autowired
    private IApplicationDocumentService applicationDocumentService;

    /**
     * 查询申请材料列表(不分页)
     */
    @PreAuthorize("@ss.hasPermi('loan:document:list')" )
    @GetMapping("/all/list" )
    public AjaxResult allList(ApplicationDocument applicationDocument) {
        List<ApplicationDocument> list = applicationDocumentService.selectApplicationDocumentList(applicationDocument);
        return success(list);
    }

    /**
     * 查询申请材料列表
     */
    @PreAuthorize("@ss.hasPermi('loan:document:list')" )
    @GetMapping("/list" )
    public TableDataInfo list(ApplicationDocument applicationDocument) {
        startPage();
        List<ApplicationDocument> list = applicationDocumentService.selectApplicationDocumentList(applicationDocument);
        return getDataTable(list);
    }

    /**
     * 导出申请材料列表
     */
    @PreAuthorize("@ss.hasPermi('loan:document:export')" )
    @Log(title = "申请材料", businessType = BusinessType.EXPORT)
    @PostMapping("/export" )
    public void export(HttpServletResponse response, ApplicationDocument applicationDocument) {
        List<ApplicationDocument> list = applicationDocumentService.selectApplicationDocumentList(applicationDocument);
        ExcelUtil<ApplicationDocument> util = new ExcelUtil<ApplicationDocument>(ApplicationDocument.class);
        util.exportExcel(response, list, "申请材料数据" );
    }

    /**
     * 获取申请材料详细信息
     */
    @PreAuthorize("@ss.hasPermi('loan:document:query')" )
    @GetMapping(value = "/{docId}" )
    public AjaxResult getInfo(@PathVariable("docId" ) Long docId) {
        return success(applicationDocumentService.selectApplicationDocumentByDocId(docId));
    }

    /**
     * 新增申请材料
     */
    @PreAuthorize("@ss.hasPermi('loan:document:add')" )
    @Log(title = "申请材料", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ApplicationDocument applicationDocument) {
        return toAjax(applicationDocumentService.insertApplicationDocument(applicationDocument));
    }

    /**
     * 修改申请材料
     */
    @PreAuthorize("@ss.hasPermi('loan:document:edit')" )
    @Log(title = "申请材料", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ApplicationDocument applicationDocument) {
        return toAjax(applicationDocumentService.updateApplicationDocument(applicationDocument));
    }

    /**
     * 删除申请材料
     */
    @PreAuthorize("@ss.hasPermi('loan:document:remove')" )
    @Log(title = "申请材料", businessType = BusinessType.DELETE)
    @DeleteMapping("/{docIds}" )
    public AjaxResult remove(@PathVariable Long[] docIds) {
        return toAjax(applicationDocumentService.deleteApplicationDocumentByDocIds(docIds));
    }
}
